package com.wechat.shopping.mall.account.service.impl;

import com.wechat.shopping.mall.account.domain.SaveWechatUserParam;
import com.wechat.shopping.mall.account.service.UserInfoService;
import com.wechat.shopping.mall.bean.po.WechatShoppingUser;
import com.wechat.shopping.mall.po.WechatShoppingUserMapper;
import com.wechat.shopping.mall.util.Constant;
import com.wechat.shopping.mall.util.ResponseMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
public class UserInfoServiceImpl implements UserInfoService {

    private static final Logger LOG = LoggerFactory.getLogger(UserInfoServiceImpl.class);

    @Autowired
    private WechatShoppingUserMapper wechatShoppingUserMapper;

    @Override
    @Transactional(readOnly = false)
    public ResponseMessage saveUser(SaveWechatUserParam user) {
        WechatShoppingUser userInfo = new WechatShoppingUser();
        BeanUtils.copyProperties(user,userInfo);
        wechatShoppingUserMapper.insertSelective(userInfo);
        return ResponseMessage.ok();
    }

    @Override
    @Transactional(readOnly = false)
    public int updateUser(SaveWechatUserParam user, Integer userId) {
        WechatShoppingUser userInfo = new WechatShoppingUser();
        BeanUtils.copyProperties(user,userInfo);
        userInfo.setId(userId);
        return wechatShoppingUserMapper.updateByPrimaryKeySelective(userInfo);
    }

    @Override
    @Transactional(readOnly = false)
    public int deleteUser(Integer userId) {
        WechatShoppingUser user = wechatShoppingUserMapper.selectByPrimaryKey(userId);
        //设置用户逻辑删除
        user.setIsdel(Constant.ONE_BYTE);
        return wechatShoppingUserMapper.updateByPrimaryKey(user);
    }
}
